﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DXApplicationTangche.UC.ImpUC
{
    public partial class XtraUserControl分页 : DevExpress.XtraEditors.XtraUserControl
    {
        private int curPage = 1;//当前页数
        private int pageSize = 500;//一页显示条数
        public delegate void GetPageDataEvents(int curPage);//定义委托
        public event GetPageDataEvents williamPagerEvent;//定义事件
        public XtraUserControl分页()
        {
            InitializeComponent();
        }

        public void changePage()
        {
            if (this.williamPagerEvent != null)
            {
                this.williamPagerEvent(this.curPage);
                this.spinEdit页数.Value = Convert.ToDecimal(this.curPage);
            }
        }

        private void simpleButton上一页_Click(object sender, EventArgs e)
        {
            if (this.curPage == 1)
            {
                MessageBox.Show("已到首页");
                return;
            }
            else
            {
                this.curPage--;
                this.changePage();
            }
        }

        private void simpleButton下一页_Click(object sender, EventArgs e)
        {
            this.curPage++;
            this.changePage();
        }

        private void spinEdit页数_ValueChanged(object sender, EventArgs e)
        {
            if (this.spinEdit页数.Value <= 0)
            {
                MessageBox.Show("页数过小");
                this.spinEdit页数.Value = Convert.ToDecimal(this.curPage);
                return;
            }
            else
            {
                this.curPage = Convert.ToInt32(this.spinEdit页数.Value);
            }
            this.changePage();
        }

        private void simpleButton首页_Click(object sender, EventArgs e)
        {
            this.curPage = 1;
            this.changePage();
        }
    }
}
